const mongoose = require('mongoose');
const pagination = require('mongoose-sex-page');
const { Article } = require('../../model/article')

module.exports = async (req, res) => {
    // page 指定当前页
    // size 指定每页显示的数据条数,5
    // display 指定客户端要显示的页码数量
    // console.log(req.query);
    if (req.query.page == undefined) {
        var page = 1
    } else {
        var page = req.query.page - 0
    }
    if (req.route.path == '/') {
        var status = true
    } else {
        var status = false
    }
    try {
        var data = await pagination(Article).find({ status }).page(page).size(7).select('-content').exec()
    } catch (err) {
        return res.send({
            data: null,
            meta: {
                status: 400,
                msg: '请求失败'
            }
        })
    }
    res.send({
        data,
        meta: {
            status: 200,
            msg: '请求成功'
        }
    })
}